package com.kfm.pm;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateExample {

    public static void main(String[] args) {
        // 获取当前日期
        LocalDate localDate = LocalDate.now();
        // year - month - date
        LocalDate localDate1 = LocalDate.of(2023, 10, 1);
        // 将 String (yyyy-MM-dd) --> LocalDate
        LocalDate localDate2 = LocalDate.parse("2323-03-23");
        System.out.println(localDate);
        System.out.println(localDate1);
        System.out.println(localDate2);

        //
        System.out.println(localDate.getYear());
        System.out.println(localDate.getMonth());
        System.out.println(localDate.getDayOfMonth());
        System.out.println(localDate.getDayOfYear());
        System.out.println(localDate.getDayOfWeek());

        System.out.println(localDate.isLeapYear());

        System.out.println(localDate.plusDays(-2));
        System.out.println(localDate.plusWeeks(1));
        System.out.println(localDate.minusDays(-2));
        //
        LocalDate localDate3 = localDate.plusWeeks(1);
        System.out.println(localDate1.isAfter(localDate3)); // true
        System.out.println(localDate1.isBefore(localDate3)); // false
        System.out.println(localDate1.isEqual(localDate3)); // false

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yy/MM/dd");
        String format = localDate3.format(dateTimeFormatter);
        System.out.println(format);
    }
}
